home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / misc / OpalDev.lha / Examples / show24.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-06  |  8.4 KB  |  392 lines

  1. #include <opal/opallib.h>
  2. #include <workbench/icon.h>
  3. #include <workbench/workbench.h>
  4. #include <workbench/startup.h>
  5. #include <intuition/intuitionbase.h>
  6. #include <proto/all.h>
  7. #include <string.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11.  
  12. #define VERSION "1.3"
  13.  
  14.     /* 2.0 style version string for the VERSION command */
  15. char Version[] = "\0$VER: Show24 " VERSION " (5.11.92)";
  16.  
  17. struct IntuitionBase *IntuitionBase;
  18. struct GfxBase *GfxBase;
  19. struct OpalBase *OpalBase;
  20. struct OpalScreen *OScrn;
  21. struct WBArg *WBArg;
  22. BOOL FromWB;
  23. UBYTE *Button = (UBYTE *)0xbfe001;        /* Nasty */
  24.  
  25. #define OR ||
  26. #define AND &&
  27.  
  28. char Banner[] = "Show24 V"VERSION" by Martin Boyd, ©1992 Opal Technology Pty Ltd.\n";
  29.  
  30. void Show_Pic (char *Name);
  31. void Clean_Up (char *String,int RetCode);
  32. char *WB_Arg (void);
  33. int Num_WB_Args (struct WBStartup *ArgMsg);
  34.  
  35. void Open_BGScreen (void);
  36. void Close_BGScreen (void);
  37. static struct Screen *BGScrn;
  38.  
  39. void App_Wait (void);
  40. void Error_Msg (char *String);
  41.  
  42.  
  43. void main (int argc,char *argv[])
  44. {
  45.    int i,NumArgs;
  46.    char *Name;
  47.  
  48.     if (argc==0)
  49.         { NumArgs = Num_WB_Args ((struct WBStartup *)argv);
  50.           FromWB = TRUE;
  51.         }
  52.     else
  53.         NumArgs = argc-1;
  54.  
  55.     if (!FromWB)
  56.         puts (Banner);
  57.  
  58.     GfxBase = (struct GfxBase *) OpenLibrary ("graphics.library",0L);
  59.     IntuitionBase = (struct IntuitionBase *) OpenLibrary ("intuition.library",0L);
  60.     if ((GfxBase==NULL) OR (IntuitionBase==NULL))
  61.         Clean_Up (NULL,10);
  62.  
  63.     OpalBase = (struct OpalBase *) OpenLibrary ("opal.library",0L);
  64.     if (OpalBase==0L)
  65.         Clean_Up ("Can't open opal.library\n",10);
  66.     OScrn = NULL;
  67.  
  68.     if ((FromWB) AND (NumArgs==0))
  69.         { App_Wait();
  70.           Clean_Up (NULL,0);
  71.         }
  72.  
  73.     if (NumArgs<1)
  74.         Clean_Up ("Usage: Show24 File\n",0);
  75.  
  76.  
  77.     for (i=1; i<=NumArgs; i++)
  78.         { if (FromWB)
  79.             Name = WB_Arg();
  80.           else
  81.             Name = argv[i];
  82.           Show_Pic (Name);
  83.         }
  84.  
  85.     Clean_Up (NULL,0);
  86. }
  87.  
  88.  
  89. void Show_Pic (char *Name)
  90. {
  91.    long Err;
  92.  
  93.     Err = LoadIFF24 (NULL,Name,VIRTUALSCREEN24);
  94.     if (Err < OL_ERR_MAXERR)
  95.         { if (Err==OL_ERR_OPENFILE)
  96.             Error_Msg ("Error opening file!!");
  97.           else if ((Err==OL_ERR_NOTILBM) OR (Err==OL_ERR_BADIFF)
  98.             OR (Err==OL_ERR_FORMATUNKNOWN))
  99.             Error_Msg ("Not a recognised file format!!");
  100.           else if (Err==OL_ERR_OUTOFMEM)
  101.             Error_Msg ("Out of memory!!\n");
  102.           else if (Err==OL_ERR_CTRLC)
  103.             Error_Msg ("Aborted");
  104.           else
  105.             Error_Msg ("Error displaying image!!");
  106.           return;
  107.         }
  108.     if (BGScrn==NULL)
  109.         Open_BGScreen ();
  110.     OScrn = (struct OpalScreen *) Err;
  111.     Err = (long)LowMemUpdate24 (OScrn,0);
  112.     if ((Err>OL_ERR_MAXERR) AND (!(OScrn->Flags&ILACE24)))
  113.         { AutoSync24 (TRUE);
  114.           Err = (long)LowMemUpdate24 (OScrn,6);
  115.         }
  116.     FreeScreen24 (OScrn);
  117.     if (Err < OL_ERR_MAXERR)
  118.         { CloseScreen24 ();
  119.           if (Err==OL_ERR_OUTOFMEM)
  120.             Error_Msg ("Out of memory!!");
  121.           else if (Err==OL_ERR_CANTCLOSE)
  122.             Error_Msg ("OpalVision Display in Use.");
  123.           else
  124.             Error_Msg ("Error Displaying image!!");
  125.           return;
  126.         }
  127.     AutoSync24 (TRUE);
  128.  
  129.     while (!(*Button & (1<<6)));
  130.     while (*Button & (1<<6));
  131.  
  132.     CloseScreen24();
  133. }
  134.  
  135. int Num_WB_Args (struct WBStartup *ArgMsg)
  136. {
  137.     WBArg = ArgMsg->sm_ArgList;
  138.     return (ArgMsg->sm_NumArgs-1);
  139. }
  140.  
  141.  
  142. char *WB_Arg (void)
  143. {
  144.     WBArg++;
  145.     CurrentDir (WBArg->wa_Lock);
  146.     return (WBArg->wa_Name);
  147. }
  148.  
  149. void _abort (void)
  150. {
  151.     Clean_Up (NULL,0);
  152. }
  153.  
  154.  
  155. void Clean_Up (char *String,int RetCode)
  156. {
  157.  
  158.     if (OpalBase!=NULL)
  159.         { CloseScreen24 ();
  160.           CloseLibrary ((struct Library *)OpalBase);
  161.         }
  162.     if (String!=NULL)
  163.         Error_Msg (String);
  164.     Close_BGScreen ();
  165.     if (IntuitionBase!=NULL) CloseLibrary ((struct Library *)IntuitionBase);
  166.     if (GfxBase!=NULL) CloseLibrary ((struct Library *)GfxBase);
  167.     exit (RetCode);
  168. }
  169.  
  170.  
  171.  
  172. /*  Open a standard screen intuition so that it will function
  173.  * correctly with the AA chip set in multi sync mode.
  174.  */
  175.  
  176. static struct NewScreen BGNewScreen = {
  177.     0,0,320,2,1,(UBYTE)-1,(UBYTE)-1,0,
  178.     CUSTOMSCREEN|SCREENQUIET,
  179.     NULL,NULL,NULL,NULL
  180. };
  181.  
  182.  
  183. static USHORT BGPalette[] = { 0x0001 };
  184.  
  185. void Open_BGScreen (void)
  186. {
  187.    struct MonitorInfo MonitorInfo;
  188.    struct DisplayInfo DisplayInfo;
  189.    DisplayInfoHandle Handle;
  190.    ULONG ModeID;
  191.    LONG Result;
  192.  
  193.     if (IntuitionBase->LibNode.lib_Version<36) return;
  194.     ModeID = GetVPModeID (&IntuitionBase->FirstScreen->ViewPort);
  195.     Handle = FindDisplayInfo (ModeID);
  196.     Result = GetDisplayInfoData (Handle,(UBYTE *)&MonitorInfo,
  197.             sizeof (struct MonitorInfo),DTAG_MNTR,NULL);
  198.     Result = GetDisplayInfoData (Handle,(UBYTE *)&DisplayInfo,
  199.             sizeof (struct DisplayInfo),DTAG_DISP,NULL);
  200.  
  201.     /*  If line frequency if >15Khz, we must open
  202.      * a low scan rate frequency screen.
  203.      */
  204.  
  205.     if (MonitorInfo.TotalColorClocks<220)
  206.         { if (DisplayInfo.PropertyFlags & DIPF_IS_PAL)
  207.             BGNewScreen.Height = 256;
  208.           else
  209.             BGNewScreen.Height = 200;
  210.           BGScrn = OpenScreen (&BGNewScreen);
  211.           if (BGScrn!=NULL)
  212.             LoadRGB4 (&BGScrn->ViewPort,BGPalette,1L);
  213.         }
  214. }
  215.  
  216. void Close_BGScreen (void)
  217. {
  218.     if (BGScrn!=NULL)
  219.         CloseScreen (BGScrn);
  220.     BGScrn = NULL;
  221. }
  222.  
  223.  
  224.  
  225. /* Start an AppIcon and wait for messages.
  226.  */
  227.  
  228. extern struct DiskObject AppObject;
  229. struct Library *WorkbenchBase;
  230.  
  231. BOOL Info_Req (void);
  232.  
  233.  
  234. void App_Wait (void)
  235. {
  236.    struct MsgPort *AppPort;
  237.    struct AppIcon *AppIcon;
  238.    struct AppMessage *AppMsg;
  239.    BPTR OldDir;
  240.    int i;
  241.  
  242.     WorkbenchBase = OpenLibrary ("workbench.library",36L);
  243.     if (WorkbenchBase==NULL) return;
  244.     AppPort = CreateMsgPort ();
  245.     if (AppPort==NULL)
  246.         { CloseLibrary (WorkbenchBase);
  247.           return;
  248.         }
  249.  
  250.     AppIcon = AddAppIconA (0,NULL,"Show24",AppPort,NULL,&AppObject,NULL);
  251.     if (AppIcon==NULL)
  252.         { DeleteMsgPort (AppPort);
  253.           CloseLibrary (WorkbenchBase);
  254.           return;
  255.         }
  256.  
  257.     /* Wait for App Messages */
  258.  
  259.     FOREVER
  260.         { WaitPort (AppPort);
  261.           while (AppMsg = (struct AppMessage *)GetMsg (AppPort))
  262.             { if (AppMsg->am_NumArgs==0L)
  263.                 { if (!Info_Req ())
  264.                     { RemoveAppIcon (AppIcon);
  265.                       DeleteMsgPort (AppPort);
  266.                       CloseLibrary (WorkbenchBase);
  267.                       return;
  268.                     }
  269.                 }
  270.               else if (AppMsg->am_NumArgs>0)
  271.                 { for (i=0; i<AppMsg->am_NumArgs; i++)
  272.                     { OldDir = CurrentDir (AppMsg->am_ArgList[i].wa_Lock);
  273.                       Show_Pic (AppMsg->am_ArgList[i].wa_Name);
  274.                       CurrentDir (OldDir);
  275.                     }
  276.                 }
  277.             }
  278.           Close_BGScreen ();
  279.         }
  280. }
  281.  
  282.  
  283.  
  284. char Banner2[] = "Show24 V"VERSION" ©1992 Opal Technology";
  285.  
  286. struct EasyStruct MyES = 
  287.     { sizeof (struct EasyStruct),
  288.       0,
  289.       (UBYTE *)Banner2,
  290.       (UBYTE *)"To display images, drop their\nicons onto this icon.\nTo Remove Show24 select quit.",
  291.       (UBYTE *)"Continue|Quit"
  292.     };
  293.  
  294.  
  295.  
  296.  
  297.  
  298. BOOL Info_Req (void)
  299. {
  300.    BOOL Res;
  301.  
  302.     if (IntuitionBase->LibNode.lib_Version<36)
  303.         return (TRUE);
  304.     Res = EasyRequestArgs (NULL,&MyES,NULL,NULL);
  305.     return (Res);
  306. }
  307.  
  308.  
  309. struct EasyStruct ErrorES = 
  310.     { sizeof (struct EasyStruct),
  311.       0,
  312.       (UBYTE *)Banner2,
  313.       NULL,
  314.       (UBYTE *)"OK"
  315.     };
  316.  
  317.  
  318. void Error_Msg (char *String)
  319. {
  320.  
  321.     if (String==NULL) return;
  322.     if (!FromWB)
  323.         { puts (String);
  324.           return;
  325.         }
  326.  
  327.     if (IntuitionBase->LibNode.lib_Version<36)
  328.         return;
  329.     ErrorES.es_TextFormat = (UBYTE *)String;
  330.     EasyRequestArgs (NULL,&ErrorES,NULL,NULL);
  331. }
  332.  
  333.  
  334. USHORT IconData[] = {
  335.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  336.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  337.     0x1FFF,0xFFFF,0xFC00,0x0000,0x1000,0x0000,0x0400,0x0000,
  338.     0x10AA,0xAABA,0x8400,0x0000,0x12AA,0xAAFA,0xA400,0x0000,
  339.     0x12AA,0xABFA,0xA40F,0x0700,0x12AA,0xAFFA,0xA41F,0x8F80,
  340.     0x12AA,0xBFFF,0xFF8D,0xDF80,0x12AA,0xBFFF,0xFFC3,0xFF80,
  341.     0x12AA,0xBFFF,0xFFC7,0xBFC0,0x12AA,0xAFFF,0xFFCF,0x1FE0,
  342.     0x12AA,0xABFA,0xA41F,0x8380,0x12AA,0xAAFA,0xA40F,0xC180,
  343.     0x10AA,0xAABA,0x8400,0x0000,0x1000,0x0000,0x0400,0x0000,
  344.     0x1FFF,0xFFFF,0xFC00,0x0000,0x007F,0x003F,0x8000,0x0000,
  345.     0x0100,0x0000,0x2000,0x0000,0x0200,0x0000,0x1000,0x0000,
  346.     0x03FF,0xFFFF,0xF000,0x0000,0x0000,0x0000,0x0000,0x0000,
  347.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  348.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  349.     0x0FFF,0xFFFF,0xF800,0x0000,0x0E00,0x0010,0x3800,0x0000,
  350.     0x0C00,0x0070,0x1800,0x0000,0x0C00,0x01F0,0x180F,0x0700,
  351.     0x0C00,0x07F0,0x1819,0x8F00,0x0C00,0x1FFF,0xFF81,0x9B00,
  352.     0x0C00,0x3FFF,0xFF83,0x3300,0x0C00,0x0FFF,0xFF86,0x3FC0,
  353.     0x0C00,0x03F0,0x000C,0x0300,0x0C00,0x00F0,0x181F,0x8300,
  354.     0x0C00,0x0030,0x1800,0x0000,0x0E00,0x0000,0x3800,0x0000,
  355.     0x0FFF,0xFFFF,0xF800,0x0000,0x0000,0x0000,0x0000,0x0000,
  356.     0x0000,0xFFC0,0x0000,0x0000,0x00FF,0xFFFF,0xC000,0x0000,
  357.     0x01FF,0xFFFF,0xE000,0x0000,0x0000,0x0000,0x0000,0x0000
  358. };
  359.  
  360. struct Image IconImage = {
  361.     0,0,
  362.     59,23,
  363.     2,
  364.     IconData,
  365.     0x0003,0x0000,
  366.     NULL
  367. };
  368.  
  369. struct DiskObject AppObject =
  370.     { NULL,
  371.       NULL,
  372.         { NULL,
  373.           0,0,
  374.           59,23,
  375.           NULL,
  376.           NULL,
  377.           NULL,
  378.           (APTR)&IconImage,
  379.           NULL,NULL,NULL,NULL,
  380.           NULL,NULL
  381.         },
  382.       NULL,
  383.       NULL,        /* NAME */
  384.       NULL,
  385.       NO_ICON_POSITION,
  386.       NO_ICON_POSITION,
  387.       NULL,
  388.       NULL,
  389.       NULL
  390.     };
  391.  
  392.